# coding=utf-8
import requests
import pyperclip
url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl={}&tl={}&dt=t&q={}&ie=UTF-8&oe=UTF-8"
print("英语:en")
print("中文(繁体):zh-TW")
print("法语:fr")
print("俄语:ru")
print("日语:ja")
print("越南语:vi")
print("波兰语:pl")
print("德语:de")
print("韩语:ko")
print("其他自己查：http://board.locoy.com/?post=94")
print("*******************************************")

la = input("输入需要转换的语言（例如：en）：")
while True:
    im=input("输入需要转换的汉字：")

    text = ""
    translation1 = ""
    translation2 = ""
    full_url = url.format("zh-CN", la, im)
    try:
        r = requests.get(full_url)
    except:
        print("网络错误或其他")
    for item in r.json()[0]:
        if item[0]!=None:
            translation1+=item[0]

    # translation = r.json()[0][0][0]
    #print("英语：")
    #print(translation1)

    # normalizedText = translation.replace('\n', ' ')
    full_url = url.format(la,"zh-CN",translation1)
    try:
        r = requests.get(full_url)
    except:
        print("网络错误或其他")


    for item in r.json()[0]:
        if item[0]!=None:
            translation2+=item[0]
    # translation = r.json()[0][0][0]
    #print("汉语：")
    #print(translation2)
    #print(type(translation2))
    pyperclip.copy(translation2)
    # print(r.text)
    print("*************************************************")
    print("*已复制到剪切板，直接粘贴即可（当前语言:"+la+"）*")
    print("*************************************************")
    # & ie = UTF - 8 & oe = UTF - 8

